﻿Public Class Form5
    ' 索引編號 0 ~ 5 , 共有 6 個項目
    Dim CheckBoxArray(5) As CheckBox

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        GroupBox2.Enabled = True
        GroupBox3.Enabled = False
        CheckBox3.Checked = False
        CheckBox4.Checked = False
        CheckBox5.Checked = False
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        ' 設定 GroupBox3 控制項是否為可使用的狀態
        GroupBox3.Enabled = True
        GroupBox2.Enabled = False

        ' 將 GroupBox2 內的 CheckBox 設為未勾選
        CheckBox1.Checked = False
        CheckBox2.Checked = False
        CheckBox3.Checked = False
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As String
        Dim Count As Integer

        s = ""
        ' 檢查是否尚未勾選任何項目
        For i = 0 To 5
            If CheckBoxArray(i).Checked Then
                s &= CheckBoxArray(i).Text & vbNewLine
                Count += 1
            End If
        Next
        'For Each cb As CheckBox In CheckBoxArray
        '    If cb.Checked Then
        '        s &= cb.Text & vbNewLine
        '        Count += 1
        '    End If
        'Next

        If Count = 0 Then
            MessageBox.Show("尚未勾選遊戲喔!", "訊息", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return
        End If

        Dim s2 As String
        s2 = "您選擇的是 " & vbNewLine & vbNewLine
        If RadioButton1.Checked Then
            s2 &= GroupBox2.Text
        Else
            s2 &= GroupBox3.Text
        End If
        s2 &= vbNewLine & vbNewLine
        s2 &= s
        ' 使用 MessageBox.Show() 顯示所有勾選的項目
        MessageBox.Show(s2, "結果", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' 設定陣列中的每個項目所代表的控制項
        CheckBoxArray(0) = CheckBox1
        CheckBoxArray(1) = CheckBox2
        CheckBoxArray(2) = CheckBox3
        CheckBoxArray(3) = CheckBox4
        CheckBoxArray(4) = CheckBox5
        CheckBoxArray(5) = CheckBox6

    End Sub
End Class